import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { ApiOkResponse, ApiTags,ApiOperation, ApiConsumes } from '@nestjs/swagger';
import { User } from './entities/user.entity';

@Controller('user')
@ApiTags('用户操作API') //文档标签分类
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Post()
  @ApiOperation ({summary:'添加一个用户'}) //接口描述信息
  create(@Body() createUserDto: CreateUserDto) {
    console.log(createUserDto);
    return this.userService.create(createUserDto);
  }

  @Get()
  @ApiOperation({summary:'查询所有用户'})
  findAll() {
    return this.userService.findAll();
  }

  @Get(':id')
  // @ApiQuery({ name: 'name', description: '用户名', required: true, type: String, })
  @ApiOperation({summary:'查询指定id用户'})
  findOne(@Param('id') id: string) {
    return this.userService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({summary:'修改指定id的用户信息'})
  update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
    return this.userService.update(+id, updateUserDto);
  }

  @Delete(':id')
  @ApiOperation({summary:'删除指定id的用户信息'})
  // @ApiOkResponse({description:'删除指定id的用户信息'})
  remove(@Param('id') id: string) {
    return this.userService.remove(+id);
  }
}
